package com.eatme.web.app.customer.service.impl;

import com.eatme.web.app.customer.service.ITbUserService;
import com.eatme.web.app.customer.dao.TbUserDao;
import com.eatme.web.app.customer.entity.TbUser;
import com.eatme.web.util.wechat.vo.WxBaseResponse;
import org.springframework.stereotype.Service;

@Service
public class TbUserServiceImpl implements ITbUserService {

    private final TbUserDao tbUserDao;

    public TbUserServiceImpl(TbUserDao tbUserDao) {
        this.tbUserDao = tbUserDao;
    }

    @Override
    public TbUser findByOpenId(String openId) {
        return tbUserDao.findByOpenId(openId);
    }

    @Override
    public TbUser buildTbUser(WxBaseResponse response) {
        TbUser tbUser = tbUserDao.save(requestToTemplate(response));
        return tbUser;
    }

    TbUser requestToTemplate(WxBaseResponse response) {
        return new TbUser(response.getOpenId(),1);
    }
}
